﻿using DependencyAnalysis.DataModel;
using NUnit.Framework;

namespace NUnitExample
{
    [TestFixture]
    public class DependencyAnalysisNamespaceHierarchyTest : DependencyTest
    {
        private SubmoduleDescriptor _algorithms;
        private SubmoduleDescriptor _algoSubstring;
        private SubmoduleDescriptor _algoCycle;
        private SubmoduleDescriptor _dataModel;
        private SubmoduleDescriptor _internalSub;
        private SubmoduleDescriptor _serialization;

        [SetUp]
        public void Initialize()
        {
            var module = DescriptorBuilder.BuildModuleDescriptor(typeof(DependencyAnalysis.Properties.IAssemblyIdentifier).Assembly);
            _algorithms = DescriptorBuilder.BuildSubmoduleDescriptor(module, "DependencyAnalysis.Algorithms");
            _algoSubstring = DescriptorBuilder.BuildSubmoduleDescriptor(module, "DependencyAnalysis.Algorithms.SubstringDetection");
            _algoCycle = DescriptorBuilder.BuildSubmoduleDescriptor(module, "DependencyAnalysis.Algorithms.CycleDetection");
            _dataModel = DescriptorBuilder.BuildSubmoduleDescriptor(module, "DependencyAnalysis.DataModel");
            _internalSub = DescriptorBuilder.BuildSubmoduleDescriptor(module, "DependencyAnalysis.Internal");
            _serialization = DescriptorBuilder.BuildSubmoduleDescriptor(module, "DependencyAnalysis.Serialization");
        }

        [Test]
        public void DataModelForbiddenReferences()
        {
            Verifier.VerifyDoesNotReferTo(_dataModel, _internalSub);
            Verifier.VerifyDoesNotReferTo(_dataModel, _serialization);
            Verifier.VerifyDoesNotReferTo(_dataModel, _algorithms);
            Verifier.VerifyDoesNotReferTo(_dataModel, _algoSubstring);
            Verifier.VerifyDoesNotReferTo(_dataModel, _algoCycle);
        }

        [Test]
        public void SerializationForbiddenReferences()
        {
            Verifier.VerifyDoesNotReferTo(_serialization, _internalSub);
            Verifier.VerifyDoesNotReferTo(_serialization, _algorithms);
            Verifier.VerifyDoesNotReferTo(_serialization, _algoSubstring);
            Verifier.VerifyDoesNotReferTo(_serialization, _algoCycle);
        }

        [Test]
        public void SubstringDetectionForbiddenReferences()
        {
            Verifier.VerifyDoesNotReferTo(_algoSubstring, _serialization);
            Verifier.VerifyDoesNotReferTo(_algoSubstring, _internalSub);
            Verifier.VerifyDoesNotReferTo(_algoSubstring, _algorithms);
            Verifier.VerifyDoesNotReferTo(_algoSubstring, _dataModel);
            Verifier.VerifyDoesNotReferTo(_algoSubstring, _algoCycle);
        }

        [Test]
        public void CycleDetectionForbiddenReferences()
        {
            Verifier.VerifyDoesNotReferTo(_algoCycle, _serialization);
            Verifier.VerifyDoesNotReferTo(_algoCycle, _internalSub);
            Verifier.VerifyDoesNotReferTo(_algoCycle, _algorithms);
            Verifier.VerifyDoesNotReferTo(_algoCycle, _dataModel);
            Verifier.VerifyDoesNotReferTo(_algoCycle, _algoSubstring);
        }
    }
}
